import request from '@/utils/request'
import { downloadPythonTemplate, downloadPDF, downloadZIP, downloadFileByType } from '@/utils/util'

const api = {
  pythonModelList: '/modelApi/pythonModelManage/pythonModelList',
  simpleSystemConfig: '/modelApi/simpleSystemConfig',
  pythonModelVersionInfo: '/modelApi/pythonModelManage/pythonModelVersionInfo',
  addTag: '/modelApi/tag',
  outputList: '/modelApi/outputList',
  inputList: '/modelApi/inputList',
  getCurrentUserIsAdmin: '/modelApi/modelTransfer/getCurrentUserIsAdmin',
  queryAiEngine: '/modelApi/deploy/python/queryAiEngine',
  getPythonOutputSet: '/modelApi/deploy/python/getPythonOutputSet',
  downloadPythonModelTemplate: '/modelApi/deploy/python/downloadPythonModelTemplate',
  queryRequirements: '/modelApi/deploy/python/queryRequirements',
  newDeploy: '/modelApi/deploy/python/newDeploy',
  parseTemplate: '/modelApi/deploy/python/parseTemplate',
  getAllUserList: '/modelApi/modelTransfer/getAllUserList',
  getModelManagerList: '/modelApi/modelTransfer/getModelManagerList',
  transferModelCharge: '/modelApi/modelTransfer/transferModelCharge',
  createNewModelManager: '/modelApi/modelTransfer/createNewModelManager',
  deleteModelManager: '/modelApi/modelTransfer/deleteModelManager',
  pythonModelStatus: '/modelApi/pythonModelManage/status',
  monitorConfig: '/modelApi/monitorConfig',
  modelFields: '/modelApi/modelFields',
  setMonitorConfig: '/modelApi/monitorConfig',
  monitorUpload: '/modelApi/monitorUpload',
  monitorEvaluate: '/modelApi/monitorEvaluate',
  deletePythonModel: '/modelApi/pythonModelManage/modelNoStatus',
  invokePDF: '/modelApi/invokePDF',
  pythonDownload: '/modelApi/modelManage/pythonDownload',
  modelTestTempDownLoad: '/modelApi/modelTestTempDownLoad',
  pythonModelUploadTestFile: '/modelApi/pythonModelUpload/testFile',
  pythonModelUploadTestResult: '/modelApi/pythonModelUpload/testResult',
  processFlow: '/modelApi/processFlow',
  systemConfig: '/modelApi/systemConfig',
  applyApproval: '/modelApi/applyApproval',
  pythonModelCalculate: '/modelApi/pythonModelCalculate',
}
const boundary = '----WebKitFormBoundary' + Math.random().toString(36).substr(2)
export function getPythonModelList(parameter) {
  return request({
    url: api.pythonModelList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function getSimpleSystemConfig(parameter) {
  return request({
    url: api.simpleSystemConfig,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function getPythonModelVersionInfo(parameter) {
  return request({
    url: api.pythonModelVersionInfo,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function addTag(parameter) {
  return request({
    url: api.addTag,
    method: 'post',
    data: parameter,
    formData: true,
  })
}

export function deleteTag(parameter) {
  return request({
    url: api.addTag,
    method: 'delete',
    data: parameter,
    formData: true,
  })
}

export function getOutputList(parameter) {
  return request({
    url: api.outputList,
    method: 'put',
    data: parameter,
    formData: true,
  })
}

export function getInputList(parameter) {
  return request({
    url: api.inputList,
    method: 'put',
    data: parameter,
    formData: true,
  })
}

export function getCurrentUserIsAdmin() {
  return request({
    url: api.getCurrentUserIsAdmin,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function queryAiEngine() {
  return request({
    url: api.queryAiEngine,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function getPythonOutputSet() {
  return request({
    url: api.getPythonOutputSet,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

/**
 * 下载Python模型模板
 * @param templateName 模板名称
 */
export function downloadPythonModelTemplate(templateName, fileName) {
  return downloadPythonTemplate(request, api.downloadPythonModelTemplate, templateName, fileName)
}

/**
 * 批量解析模板
 * @param parameter
 */
export function parseTemplate(parameter) {
  return request({
    url: api.parseTemplate,
    method: 'post',
    data: parameter,
    'Content-Type': `multipart/form-data; boundary=${boundary}`,
  })
}
/**
 * 查询Python模型需求
 */
export function queryRequirements() {
  return request({
    url: api.queryRequirements,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

/**
 * 新部署
 */
export function newDeploy(parameter) {
  return request({
    url: api.newDeploy,
    method: 'post',
    data: parameter,
    'Content-Type': `multipart/form-data; boundary=${boundary}`,
  })
}

/**
 * 获取所有用户列表
 */
export function getAllUserList(parameter) {
  return request({
    url: api.getAllUserList,
    method: 'post',
    data: parameter,
    formData: true,
    concatenate: true,
  })
}
/**
 * 获取模型管理列表
 */
export function getModelManagerList(parameter) {
  return request({
    url: api.getModelManagerList,
    method: 'post',
    data: parameter,
    formData: true,
    concatenate: true,
  })
}
/**
 * 模型负责人转移
 */
export function transferModelCharge(parameter) {
  return request({
    url: api.transferModelCharge,
    method: 'post',
    data: parameter,
    formData: true,
    concatenate: true,
  })
}
/**
 * 创建新的模型管理员
 */
export function createNewModelManager(parameter) {
  return request({
    url: api.createNewModelManager,
    method: 'post',
    data: parameter,
    formData: true,
    concatenate: true,
  })
}
/**
 * 删除模型管理员
 */
export function deleteModelManager(parameter) {
  return request({
    url: api.deleteModelManager,
    method: 'delete',
    data: parameter,
    formData: true,
    concatenate: true,
  })
}
/**
 * 设置Python模型状态
 */
export function setPythonModelStatus(parameter) {
  return request({
    url: api.pythonModelStatus,
    method: 'put',
    data: parameter,
    formData: true,
  })
}
/**
 * 获取模型监控配置
 */
export function getMonitorConfig(parameter) {
  return request({
    url: api.monitorConfig,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
/**
 * 获取模型字段
 */
export function getModelFields(parameter) {
  return request({
    url: api.modelFields,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
/**
 * 设置模型监控配置
 */
export function setMonitorConfig(parameter) {
  return request({
    url: api.setMonitorConfig,
    method: 'put',
    data: parameter,
    formData: true,
  })
}

/**
 * 上传监控模板
 * @param parameter
 */
export function uploadMonitorTemplate(parameter) {
  return request({
    url: api.monitorUpload,
    method: 'post',
    data: parameter,
    'Content-Type': `multipart/form-data; boundary=${boundary}`,
  })
}
/**
 * 模型评估
 */
export function monitorEvaluate(parameter) {
  return request({
    url: api.monitorEvaluate,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
/**
 * 设置模型监控配置
 */
export function setMonitorEvaluate(parameter) {
  return request({
    url: api.monitorEvaluate,
    method: 'put',
    data: parameter,
    formData: true,
  })
}
/**
 * 删除Python模型
 */
export function deletePythonModel(parameter) {
  return request({
    url: api.deletePythonModel,
    method: 'delete',
    data: parameter,
    formData: true,
  })
}

/**
 * 调用PDF
 */
export function invokePDF(parameter, option) {
  return downloadPDF(request, api.invokePDF, parameter, option)
}
/**
 * 下载Python模型
 */
export function downloadPythonModel(parameter, option) {
  return downloadZIP(request, api.pythonDownload, parameter, option)
}

/**
 * 模型测试文件模板下载
 */
export function modelTestTempDownLoad(parameter, option) {
  return downloadFileByType(request, api.modelTestTempDownLoad, parameter, option)
}
/**
 * 模型测试文件上传
 */
export function pythonModelUploadTestFile(parameter) {
  return request({
    url: api.pythonModelUploadTestFile,
    method: 'post',
    data: parameter,
    'Content-Type': `multipart/form-data; boundary=${boundary}`,
  })
}
/**
 * 模型测试文件结果下载
 */
export function pythonModelUploadTestResult(parameter, option) {
  return request({
    url: api.pythonModelUploadTestResult,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
/**
 * 获取系统配置
 */
export function getSystemConfig(parameter) {
  return request({
    url: api.systemConfig,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
/**
 * 模型审批流程
 */
export function processFlow(parameter) {
  return request({
    url: api.processFlow,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
/**
 * 模型审批
 */
export function applyApproval(parameter) {
  return request({
    url: api.applyApproval,
    method: 'post',
    data: parameter,
    formData: true,
  })
}
/**
 * 模型测试
 */
export function PythonModelCalculate(parameter) {
  return request({
    url: api.pythonModelCalculate,
    method: 'post',
    data: parameter,
    formData: true,
  })
}
